import Taro from '@tarojs/taro'
import { View, Text, Image, ITouchEvent } from '@tarojs/components'
import "taro-ui/dist/style/components/tabs.scss";
import "taro-ui/dist/style/components/button.scss" // 按需引入 
import ChannelStyle from '@@/channel/channelStyle';

import './index.scss'

export default function myAttention() {
  const phone = '13242438348';
  const wechat = 'lecong-master';
  const wechatImg = 'https://leconglive-wxapp-1301839528.file.myqcloud.com/%E5%B0%8F%E4%B9%90.jpg?imageView2/1/w/200/h/200';

  //复制微信
  const copyWechat = (e: ITouchEvent) => {
    Taro.setClipboardData({ data: e.target.dataset.wechat })
  }

  //拨打电话
  const callPhone = (e: ITouchEvent) => {
    Taro.makePhoneCall({
      phoneNumber: e.target.dataset.phone
    })
  }

  const saveWechatImg = () => {
    Taro.getImageInfo({ src: wechatImg })
      .then(res => {
        Taro.saveImageToPhotosAlbum({
          filePath: res.path
        }).then((imgRes) => {
          if (imgRes.errMsg === 'saveImageToPhotosAlbum:ok') {
            Taro.showToast({
              title: '图片保存成功',
              icon: 'none',
              duration: 1000,
            })
          } else {
            Taro.showToast({
              title: '图片保存失败',
              icon: 'none',
              duration: 1000,
            })
          }
        })
      })
  }

  return (
    <View className='index'>
      <View className='main'>
        <View className='tx'>
          <Image src={ASSETS_PATH + '/default_avator.png'} className='tx_img'></Image>
        </View>
        <View className='uname'>
          <Text>{ChannelStyle.appName}小乐</Text>
        </View>
        <View className='text'>
          <Text>您的专属经理，给你提供最好的服务</Text>
        </View>
        <View className='border'></View>
        <View className='tel'>
          <Text className='way'>手机号:</Text>
          <Text className='phone' onClick={callPhone} data-phone={phone}>{phone}</Text>
        </View>
        <View className='tel'>
          <Text className='way'>微信号:</Text>
          <Text className='phone' onClick={copyWechat} data-wechat={wechat}>{wechat}</Text>
        </View>
        <View className='code'>
          <Image src={wechatImg} className='code_img' onClick={saveWechatImg}></Image>
        </View>
        <View className='text1'>
          <Text>或点击保存，添加专属经理</Text>
        </View>
      </View>
    </View>
  )
}
